#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const ll INF = 1e15;

int n, m;
ll x[N];
struct Node {
  int l, r;
  ll w;
  bool operator<(const Node& o) const { return w > o.w; }
};
int rpos[N], lpos[N];
ll d[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> x[i];
  x[0] = -INF;
  x[n + 1] = INF;
  priority_queue<Node> pq;
  rep(i, 0, n) {
    pq.push(Node{i, i + 1, x[i + 1] - x[i]});
    lpos[i + 1] = i, rpos[i] = i + 1;
    d[i + 1] = x[i + 1] - x[i];
  }
  ll sum = 0;
  int cnt = 0;
  while (cnt < m) {
    Node t = pq.top();
    pq.pop();
    if (lpos[t.r] != t.l) continue;
    lpos[t.r] = rpos[t.l] = -1;
    sum += t.w, cnt++;
    ll cost = -t.w;
    // left
    int pre = lpos[t.l], nxt = rpos[t.r];
    lpos[t.l] = rpos[t.r] = 0;
    cost += d[t.l] + d[nxt];
    rpos[pre] = nxt, lpos[nxt] = pre;
    d[nxt] = cost;
    pq.push(Node{pre, nxt, cost});
  }
  cout << sum;
  return 0;
}